(function(){
    $(".back").click(function(){
        $("body,html").animate({scrollTop:0},500)
    })

    var str=window.location.href;
    str=str.split("?")[1].split("&")
    console.log(str)
    var productId=str[0].split("=")[1],
    category=decodeURI(str[1].split("=")[1]),
    productName=decodeURI(str[2].split("=")[1])
    console.log(productId,category,productName)

    $(".nav").children("div").children("a:eq(1)").html(category+">")
    $(".nav").children("div").children("a:eq(2)").html(productName+">")

    $.ajax({
        type:"GET",
        url:"http://chst.vip:1234/api/getproduct",
        data:{productid:productId}

    }).then(res=>{
        
        detail=res.result[0]
        console.log(detail)
        let html=`<p>${detail.productName}</p>
                ${detail.productImg}
                ${detail.bjShop}
        `
        $(".box").html(html)

        $(".back").click(function(){
            window.location.href="http://127.0.0.1:5500/%E9%A1%B9%E7%9B%AE/pages/shoppingList.html?categoryid="+detail.categoryId+"&category="+category
        })
    })

    $.ajax({
        type:"GET",
        url:"http://chst.vip:1234/api/getproductcom",
        data:{productid:productId}
    }).then(res=>{
        pj=res.result;
        console.log(pj)
        let html=""
        pj.forEach(function(item){
            html+=`
            <li>
                <div>
                    <p>${item.comName}</p><p>${item.comTime}</p>
                </div>
                <p>${item.comFrom}</p>
                <p>${item.comContent}</p>
            </li>
            `
        })
        $(".pj-box").html(html);
    })
    



})()

